var content = document.querySelector('.content');
var tbody1 = document.querySelector(".grade-table tbody");
var tbody2 = document.querySelector(".grade-table-fk tbody");
var targetContainer = document.querySelector('.grade-table-fk');

content.addEventListener('mouseenter', function() {
  content.style.transition = 'background-color 0.3s';
  content.style.backgroundColor = 'rgba(100,100,100,0.5)'; // 将透明度更改为 0.5，使背景色加深
});

content.addEventListener('mouseleave', function() {
  content.style.transition = 'background-color 0.3s';
  content.style.backgroundColor = 'rgba(100,100,100,0.2)'; // 将透明度恢复为 0.2，使背景色变浅
});

var data1 = [];
var data2 = [];

document.addEventListener("DOMContentLoaded", function() {
  var tmp = 0;
  $.ajax({
    url: '/management/onsiteservlet/ossStatisticsSign',                                 //url方法接口：统计签到
    method: 'POST',
    data: {
      username: "1"
    },
    success: function(response) {

        if (response.data === undefined) {
                alert("未选择课程！")
                window.location.href="livlogin_menu.html";
        }

      console.log(response);
      console.log(response.data);
      data = response.flag;
      data1 = response.data;
      console.log(data1.length);
      console.log(data1[0].Stu_sign);
      var test = data1[0].Stu_sign;     // 初态2
      if (test == "2"){
            tmp += 1;

                        if(tmp == 2){
                             alert("未发布签到或反馈！")
                             window.location.href="livlogin_menu.html";
                        }
      }
//      if (test == "2") {
//        //alert("未选择课程或未发布签到！")
//        window.location.href="livlogin_menu.html";
//      }
        else {
        // 将数据数组赋值给相应的元素
        var currentIndex = 1;
        data1.forEach(function(item) {
          var row = document.createElement("tr");
          row.innerHTML = `
            <td>${currentIndex}</td>
            <td>${item.Stu_name}</td>
            <td>${item.Cou_name}</td>
            <td>${item.Cou_time}</td>
            <td>${item.Cou_teacher}</td>
            <td>${item.Stu_sign}</td></td>
          `;
          tbody1.appendChild(row);
          currentIndex++;
        });
      }
    }
  });

                // 这里使用一个新变量，后端可以传回这个地方类似于 Signup：“已签到” 的形式

  $.ajax({
    url: '/management/onsiteservlet/ossStatisticsAdvice',                                 //url方法接口：统计反馈
    method: 'POST',
    data: {
      username: "1"
    },
    success: function(response) {
      console.log(response);
      console.log(response.data);
      data = response.flag;
      data2 = response.data;
      console.log(data2.length);
      if (data2.length == "0"){
            tmp += 1;
            //alert(tmp);

            if(tmp == 2){
                 alert("未发布签到或反馈！")
                 window.location.href="livlogin_menu.html";
            }
      }
//      if (test == "2") {
//        alert("未选择课程或未发布反馈！")
//        window.location.href="livlogin_menu.html";
//      }
        else {
        var currentIndex = 1;
        data2.forEach(function(item) {
          var row = document.createElement("tr");
          row.innerHTML = `
            <td>${currentIndex}</td>
            <td>${item.Stu_name}</td>
            <td>${item.Cou_name}</td>
            <td>${item.Cou_teacher}</td>
            <td>${item.Cou_advice}</td>
          `;
          tbody2.appendChild(row);
          currentIndex++;
        });
      }
    }
  });
                 // 使用Cou_advice来存储反馈内容

  var links = document.querySelectorAll('.sidebar ul li a');

  for (var i = 0; i < links.length; i++) {
    links[i].addEventListener('mouseenter', function() {
      this.style.transition = '0.2s';
      this.style.backgroundColor = '#679';
      this.style.borderRadius = '10px'; // 设置边缘的圆角半径为10px
    });

    links[i].addEventListener('mouseleave', function() {
      this.style.transition = '0.2s';
      this.style.backgroundColor = '';
      this.style.borderRadius = '10px'; // 鼠标移出时恢复原始边缘
    });
  }
});
